package com.yun.web;

import com.yun.pojo.User;
import com.yun.service.UserServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/user/checkCode")
public class CodeServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取请求参数
        String code = request.getParameter("code");
        UserServiceImp serviceImp = new UserServiceImp();
        User user = serviceImp.getUser(code);
        //处理ajax
        PrintWriter writer = response.getWriter();
        if(user==null){
            writer.write("OK");
        }else {
            writer.write("NO");
        }


    }
}
